#pragma once

#include "ColligereCddbDiscId.hpp"
#include "ColligereAudioDatabaseHandler.hpp"

namespace col
{

class SearchFreeDb
{
public:
	SearchFreeDb() { }
	SearchFreeDb ( const wxString &rDevice );

	class SearchResult
	{
	public:
		SearchResult() { }
		SearchResult ( const wxString &rCat, const wxString &rDiscId,
			const wxString &rTitle ) : mCat ( rCat ), mDiscId ( rDiscId ),
			mTitle ( rTitle ) { }

		const wxString &GetCategory() const { return mCat; }
		const wxString &GetDiscId() const { return mDiscId; }
		const wxString &GetTitle() const { return mTitle; }
	private:
		wxString mCat, mDiscId, mTitle;
	};

	void SetDevice ( const wxString &rDevice ) { mDiscId.SetDevice ( rDevice ); }

	typedef std::deque < const SearchResult > SearchResultDeque;

	SearchResultDeque Search();

	Artist DownloadResult ( const SearchResult &rResult );
private:
	const wxString DiscInfoToQuery();
	long ParseSearchResults ( const wxString &rFromData, SearchResultDeque &rTo );

	long GetServerResponseCode ( const wxString &rFromData ) const;

	SearchResult BuildSearchResultFromRegexMatch ( const wxRegEx &rRe, 
		const wxString &rData );

	const wxString GetServerHello() const;
	const wxString GetServerAddress() const;

	Artist ParseDatabaseItem ( const wxString &rFromData );

	CddbDiscId mDiscId;
};

}